#ifndef FEATUREFUNCTIONS_H
#define FEATUREFUNCTIONS_H

#include <vector>
#include <queue>
#include "PamImage.h"
#include "Word.h"
#define Descriptor vector<double>

using namespace std;

struct WordAStarNode{
    Word* word;
    double weight;
    double gScore;
    double hScore;
    double fScore;
    bool isOpen;
    bool isClosed;
    bool isFinish;
    WordAStarNode* previousNode;
};

struct Descriptors{
  int wordLength;
  double heightWidthRatio;
  vector<double> radonDescriptor;
  vector<int> bottomProfileDescriptor;
  vector<int> lowResolution;
};

class WordPositionCompare
{
  public:
  bool operator() (const Word* first, const Word* second) const {
    return first->left > second->left;
  }
};

vector<Word> GetBestLine(vector<Word> words);
vector<Word> ToWordVector(WordAStarNode* line);

Descriptors getDescriptors(PamImage& inImage);

PamImage getRadonTransform(PamImage& inImage, int nAngles=128, int nLines=128);
vector<double> getRadonHistogram(PamImage& radonImage, int outWidth=255);

double getHeightWidthRatioDistance(double first, double second);
double featureDistance(Descriptor featureVec1, Descriptor featureVec2);

vector<int> getBottomProfile(PamImage& wordImage);
double getBottomProfileDistance(vector<int> first, vector<int> second);

vector<int> getLowResolution(PamImage& wordImage);
double getLowResolutionDistance(vector<int> first, vector<int> second);

vector<Word> createLineWithLowestScore(vector<Word> inputWords);
vector<vector<Word*> > doCreateLineWithLowestScore(priority_queue<Word*, vector<Word*>, WordPositionCompare> orderedWords, vector<Word*> previousWords);
vector<vector<Word*> > MergeWordToPotentialTails(vector<vector<Word*> > potentialTails, Word* word, vector<Word*> previousWords, bool ignoreMaxGap);
vector<vector<Word*> > GetOnlyBestScoringLine(vector<vector<Word*> > input, int start);
bool overlaps(vector<Word*> words, Word* word);
double score(vector<Word*> words);

PamImage* lowResolutionToImage(vector<int> input);

#endif
